function mycopy(target, map = new Map()) {
  if (typeof target === "object") {
    let clone = Array.isArray(target) ? [] : {};
    if (map.get(target)) {
      return map.get(target);
    }
    map.set(target, clone);
    for (const key in target) {
      clone = mycopy(key, map);
    }
  } else {
    return target;
  }
}

